package net.oschina.simpleplus.erpc.consumer.test;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import net.oschina.simpleplus.erpc.Launcher;
import net.oschina.simpleplus.erpc.api.ERpcContainer;
import net.oschina.simpleplus.erpc.consumer.ERpcServer;
import net.oschina.simpleplus.erpc.support.ThreadPoolExecutorFactory;

public class Consumer implements InitializingBean, ApplicationContextAware{
	public static void main(String[] args) {
		new ClassPathXmlApplicationContext("application.xml");
	}
	ERpcContainer eRpcContainer = null;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		eRpcContainer = new ERpcContainer(applicationContext);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		Launcher server = new ERpcServer(
				ThreadPoolExecutorFactory.create(1, 2, 2, TimeUnit.MINUTES, 100, "Consumer-Threadpool"),
				eRpcContainer);
		try {
			server.start(10000);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
